<template>
  <div v-if="committionList.length" class="committee_info">
    <div class="model_title">赛事架构</div>
    <div class="committee_content model_content">
      <div v-for="(item, index) in committionList" :key="index" class="committee_item gl_clear">
        <div class="committee_typeName">{{ item.name }}：</div>
        <div class="gl_fl" style="width: calc(100% - 72px);">
          <div v-for="jtem in item.data" :key="jtem.id" class="committee_name">
            {{ jtem.organizationName }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import {
  api_GET_EventsManagementCompetitionOrganization
} from '@/extend/api/gameswaggerApi/app';
export default {
  name: 'CommitteeInfo',
  props: {
    gameId: {
      type: String,
      required: true,
      default: ''
    }
  },
  data() {
    return {
      committionList: []
    };
  },
  watch: {
    gameId() {
      this.getCommittionList();
    }
  },
  created() {
    this.getCommittionList();
  },
  methods: {
    // 获取指定组委会单位列表
    getCommittionList() {
      if (!this.gameId) return;
      api_GET_EventsManagementCompetitionOrganization({ competitionId: this.gameId }).then(res => {
        const committionList = res.items || [];
        this.committionList = this.handleShowCommittion(committionList);
      });
    },
    // 处理显示组委会
    handleShowCommittion(committionList) {
      const _committionList = {};
      const returnCommittionList = [];
      for (let i = 0; i < committionList.length; i++) {
        const item = committionList[i];
        _committionList[item.organizationKey] = _committionList[item.organizationKey] || [];
        _committionList[item.organizationKey].push(item);
      }
      // 主办单位
      if (_committionList.sponsor) {
        returnCommittionList.push({
          name: '主办单位',
          data: _committionList.sponsor
        });
      }
      // 承办单位
      if (_committionList.contractor) {
        returnCommittionList.push({
          name: '承办单位',
          data: _committionList.contractor
        });
      }
      // 支持单位
      if (_committionList.support) {
        returnCommittionList.push({
          name: '支持单位',
          data: _committionList.support
        });
      }
      // 协办单位
      if (_committionList.assistance) {
        returnCommittionList.push({
          name: '协办单位',
          data: _committionList.assistance
        });
      }
      if (_committionList.phone) {
        returnCommittionList.push({
          name: '联系电话',
          data: _committionList.phone
        });
      }
      return returnCommittionList;
    }
  }
};
</script>
<style>
.committee_content {
  padding: 10px 16px;
}
.committee_info .committee_item {
  font-size: 14px;
  line-height: 20px;
  color: #666666;
  margin-top: 6px;
  box-sizing: border-box;
}
.committee_info .committee_name {
  line-height: 20px;
}
.committee_typeName {
  width: 72px;
  float: left;
}
</style>
